package de.clue.corpus.twitter.bean;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import noNamespace.TweetDocument.Tweet;

import org.apache.commons.io.FileUtils;

public class FileLister {
	
	private ArrayList<DataObject> files = new ArrayList<DataObject>();
	
	public void setFiles(ArrayList<DataObject> files) {
		this.files = files;
	}


	private String parentDirectory = "";

	private String[] fileExtensions = {"xml"};

	public String getParentDirectory() {
		return parentDirectory;
	}

	public void setParentDirectory(String parentDirectory) {
		this.parentDirectory = parentDirectory;
		initList();
		
	}


	public ArrayList<DataObject> getFiles() {
		return files;
	}
	
	
	private void initList() {
		Collection<File> listFiles = FileUtils.listFiles(new File(parentDirectory), fileExtensions , false);
		
		ArrayList<DataObject> newFiles = new ArrayList<DataObject>();
		
		
		for (Iterator iterator = listFiles.iterator(); iterator.hasNext();) {
			File file = (File) iterator.next();
			DataObject dataObject = new DataObject();
			
			dataObject.setName(file.getName());
			dataObject.setPath(file.getAbsolutePath());
			
			newFiles.add(dataObject);
			
		}
		
		setFiles(newFiles);
		
	}
	

}
